#include "widget.h"
#include "ui_widget.h"
#include <QTreeWidgetItem>

//Widget::Widget(QWidget *parent)
//    : QWidget(parent)
//    , ui(new Ui::Widget)
//{
//    ui->setupUi(this);
////    ui->treeWidget->setHeaderLabel("美食");   //设置

////    QTreeWidgetItem* item1 = new QTreeWidgetItem();
////    item1->setText(0,"荤菜");
////    ui->treeWidget->addTopLevelItem(item1);

////    QTreeWidgetItem* item2 = new QTreeWidgetItem();
////    item2->setText(0,"素菜");
////    ui->treeWidget->addTopLevelItem(item2);

////    QTreeWidgetItem* item3 = new QTreeWidgetItem();
////    item3->setText(0,"主食");
////    ui->treeWidget->addTopLevelItem(item3);
//}

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
}
Widget::~Widget()
{
    delete ui;
}

//Widget::Widget(QWidget *parent)
//    : QWidget(parent)
//    , ui(new Ui::Widget)
//{
//    ui->setupUi(this);
////    ui->tableWidget->insertRow(0);
////    ui->tableWidget->insertRow(1);
////    ui->tableWidget->insertRow(2);
////    ui->tableWidget->insertColumn(0);
////    ui->tableWidget->insertColumn(1);
////    ui->tableWidget->insertColumn(2);

////    //设置表头名
////    ui->tableWidget->setHorizontalHeaderItem(0,new QTableWidgetItem("周一"));
////    ui->tableWidget->setHorizontalHeaderItem(1,new QTableWidgetItem("周二"));
////    ui->tableWidget->setHorizontalHeaderItem(2,new QTableWidgetItem("周三"));

////    ui->tableWidget->setVerticalHeaderItem(0,new QTableWidgetItem("第一节"));
////    ui->tableWidget->setVerticalHeaderItem(1,new QTableWidgetItem("第二节"));
////    ui->tableWidget->setVerticalHeaderItem(2,new QTableWidgetItem("第三节"));

////    //向表格中添加内容
////    ui->tableWidget->setItem(0,0,new QTableWidgetItem("语文"));
////    ui->tableWidget->setItem(1,1,new QTableWidgetItem("数学"));
////    ui->tableWidget->setItem(2,2,new QTableWidgetItem("英语"));
//}


//Widget::Widget(QWidget *parent)
//    : QWidget(parent)
//    , ui(new Ui::Widget)
//{
//    ui->setupUi(this);
//    ui->listWidget->addItem("C++");
//    ui->listWidget->addItem("Java");
//    ui->listWidget->addItem("PHP");
//}

//void Widget::on_listWidget_currentItemChanged(QListWidgetItem *current, QListWidgetItem *previous)
//{
//    if(current != nullptr && previous != nullptr)
//    {
//        qDebug() << "当前选中：" << current->text() << " 之前选中:" << previous->text();
//    }
//}

//void Widget::on_pushButton_clicked()
//{
//    const QString content = ui->lineEdit->text();
//    if(!content.isEmpty())
//    {
//        ui->listWidget->addItem(content);
//    }
//}

//void Widget::on_pushButton_2_clicked()
//{
//    int curRow = ui->listWidget->currentRow();
//    ui->listWidget->takeItem(curRow);
//}

//void Widget::on_pushButton_addRow_clicked()
//{
//    int rowCnt = ui->tableWidget->rowCount();
//    ui->tableWidget->insertRow(rowCnt);
//    ui->tableWidget->setVerticalHeaderItem(rowCnt,new QTableWidgetItem(ui->lineEdit->text()));
//}

//void Widget::on_pushButton_delSelectRow_clicked()
//{
//    //获取选中行的行号
//    int rowCnt = ui->tableWidget->currentRow();
//    ui->tableWidget->removeRow(rowCnt);
//}

//void Widget::on_pushButton_addCol_clicked()
//{
//    int colCnt = ui->tableWidget->columnCount();
//    ui->tableWidget->insertColumn(colCnt);
//    ui->tableWidget->setHorizontalHeaderItem(colCnt,new QTableWidgetItem(ui->lineEdit_2->text()));
//}

//void Widget::on_pushButton_delSelectCol_clicked()
//{
//    //获取选中列号
//    int colCnt = ui->tableWidget->currentColumn();
//    ui->tableWidget->removeColumn(colCnt);
//}

//void Widget::on_pushButton_clicked()
//{
//    const QString content = ui->lineEdit->text();
//    if(content.isEmpty())
//    {
//        return;
//    }
//    QTreeWidgetItem* item = new QTreeWidgetItem();
//    item->setText(0,content);
//    ui->treeWidget->addTopLevelItem(item);
//}

//void Widget::on_pushButton_2_clicked()
//{
//    const QString content = ui->lineEdit->text();
//    if(content.isEmpty())
//    {
//        return;
//    }
//    //获取当前选中节点
//    QTreeWidgetItem* curItem = ui->treeWidget->currentItem();
//    if(curItem == nullptr)
//        return;

//    QTreeWidgetItem* item = new QTreeWidgetItem();
//    item->setText(0,content);
//    curItem->addChild(item);    //添加至父节点中
//    curItem->setExpanded(true); //展开父节点
//}

//void Widget::on_pushButton_3_clicked()
//{
//    QTreeWidgetItem* curItem = ui->treeWidget->currentItem();
//    if(curItem == nullptr)
//        return;
//    //获取当前节点得父节点
//    QTreeWidgetItem* parent = curItem->parent();
//    if(parent == nullptr)
//    {
//        //顶层节点
//        int index = ui->treeWidget->indexOfTopLevelItem(curItem);
//        ui->treeWidget->takeTopLevelItem(index);
//    }
//    else
//    {
//        parent->removeChild(curItem);
//    }
//}
